<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>计算字数案例</title>
  <style>
    input {
      width: 300px;
      height: 100px;
      transition: all 3s;
    }

    div {
      opacity: 0;
      ;
    }

    /* 表单伪类选择器 获取光标*/
    input:focus {
      height: 200px;
    }
  </style>
</head>

<body>
  <input type="text" placeholder="请输入文字">
  <div>字数是:</div>
  <script>
    const input = document.querySelector('input')
    const div = document.querySelector('div')
    input.addEventListener('focus', function () {
      // console.log(1);
      div.style.opacity = 1
    })

    input.addEventListener('input', function () {
      div.innerHTML = `字数是:${input.value.length}`
    })

  </script>
</body>

</html>